package handle;

import common.Constants.ServiceConstant;
import common.Result;
import dataBean.CourseRegisterPOJO;
import dataBean.UserInfoDo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import service.CourseService;
import service.UserService;
import service.VerifyService;

/**
 * Created by allen on 11/19/15.
 */
@Controller
@RequestMapping("ssms/course")
public class RegisterCourseHandler {

    @Autowired
    private CourseService courseService;

    @Autowired
    private VerifyService verifyService ;

    @RequestMapping(value = "/register", method = RequestMethod.POST)
    public @ResponseBody
    Result process( @RequestBody CourseRegisterPOJO courseRegisterPOJO, @RequestHeader String token ){
//TEST
        System.out.println("request accepted!");

        Result result = verifyService.verify(token, ServiceConstant.ADMIN_LEVEL) ;

        if( result.isSucces() ){
//TEST
            System.out.println("courseInfoDo.name" + courseRegisterPOJO.getCourseInfoDo().getName());
            System.out.println("students.length" + courseRegisterPOJO.getStudents().size());
            for (int id : courseRegisterPOJO.getStudents()) {
                System.out.println("student id " + id);
            }

            result = courseService.addStudentList(courseRegisterPOJO.getCourseInfoDo(), courseRegisterPOJO.getStudents());

        }

        return  result ;
    }

}   //RegisterCourseHandler
